package org.eyeTopLight.controller;

import org.eyeTopLight.po.Category;
import org.eyeTopLight.po.CommonResult;
import org.eyeTopLight.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * BasicController负责首页的全部信息和个人信息的展示
 */
@RestController
public class BasicController {

    private static final Logger logger = LoggerFactory.getLogger(BasicController.class);

    @Resource
    private CategoryService categoryService;

    /**（已完成）
     * 返回一个分类下的所有小分类
     * @param symbol frame表示镜架类，len表示镜片类，sunglasses表示太阳镜，accessory表示配件
     * @return
     */
    @GetMapping("/basic/getBannerCategories")
    public CommonResult getBannerCategory(String symbol){
        try{
            List<Category> categories = categoryService.getCategories(symbol);
            return new CommonResult(200,"success" ,categories);
        }
        catch (Exception e){
            logger.error("数据库Category表操作失败",e);
            return new CommonResult(500,"服务器内部错误");
        }
    }
}
